#!/bin/bash

function msg {
	printf "\e[1;32m>>>>>>\e[m %s\n" "$1"
}
function msg2 {
	printf "\e[1;34m>>>>>>\e[m %s\n" "$1"
}

msg "Olarila.com - All About Vanilla Hackintosh"

osascript <<EOT
tell application "Finder"
 activate
 display alert "Check OLARILA.COM for Professional Hackintosh support!"
end tell
EOT

echo "You need Xcode installed to using this program!"
echo "            "
echo "##### !!! DOWNLOADING FILES - This may take a while !!! #####"
echo "            "
mkdir /$HOME/Desktop/Lilu4All
cd /$HOME/Desktop/Lilu4All
git clone https://github.com/acidanthera/MacKernelSDK
git clone https://github.com/acidanthera/Lilu
git clone https://github.com/acidanthera/RestrictEvents
git clone https://github.com/acidanthera/AppleALC
git clone https://github.com/acidanthera/AirportBrcmFixup
git clone https://github.com/acidanthera/EmeraldSDHC
git clone https://github.com/acidanthera/WhateverGreen
git clone https://github.com/acidanthera/NVMeFix
git clone https://github.com/acidanthera/BrightnessKeys
git clone https://github.com/acidanthera/HibernationFixup
git clone https://github.com/acidanthera/DebugEnhancer
git clone https://github.com/acidanthera/CpuTscSync
git clone https://github.com/acidanthera/CryptexFixup
git clone https://github.com/acidanthera/FeatureUnlock
git clone https://github.com/acidanthera/CPUFriend
git clone https://github.com/acidanthera/VoodooPS2
git clone https://github.com/acidanthera/IntelMausi
git clone https://github.com/acidanthera/RTCMemoryFixup
git clone https://github.com/acidanthera/VirtualSMC
git clone https://github.com/acidanthera/MacHyperVSupport
git clone https://github.com/Mieze/RTL8111_driver_for_OS_X
git clone https://github.com/Mieze/AtherosE2200Ethernet
git clone https://github.com/Mieze/RealtekRTL8100
git clone https://github.com/acidanthera/BrcmPatchRAM
git clone https://github.com/acidanthera/VoodooInput
git clone https://github.com/lvs1974/ThunderboltFixup
git clone https://github.com/ChefKissInc/ForgedInvariant
git clone https://github.com/ChefKissInc/NootedRed
git clone https://github.com/b00t0x/CpuTopologyRebuild

echo "            "
echo "##### !!! COPY LILU TO FOLDERS !!! #####"
echo "            "
cd /$HOME/Desktop/Lilu4All
cp -r ./MacKernelSDK ./Lilu
xcodebuild -project ./Lilu/Lilu.xcodeproj -configuration Debug clean build ARCHS=x86_64 ONLY_ACTIVE_ARCH=YES CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All
cp -r ./Release/Lilu.kext ./RestrictEvents
cp -r ./Release/Lilu.kext ./AppleALC
cp -r ./Release/Lilu.kext ./AirportBrcmFixup
cp -r ./Release/Lilu.kext ./EmeraldSDHC
cp -r ./Release/Lilu.kext ./WhateverGreen
cp -r ./Release/Lilu.kext ./NVMeFix
cp -r ./Release/Lilu.kext ./BrightnessKeys
cp -r ./Release/Lilu.kext ./HibernationFixup
cp -r ./Release/Lilu.kext ./DebugEnhancer
cp -r ./Release/Lilu.kext ./CpuTscSync
cp -r ./Release/Lilu.kext ./CryptexFixup
cp -r ./Release/Lilu.kext ./FeatureUnlock
cp -r ./Release/Lilu.kext ./CPUFriend
cp -r ./Release/Lilu.kext ./VoodooPS2
cp -r ./Release/Lilu.kext ./IntelMausi
cp -r ./Release/Lilu.kext ./RTCMemoryFixup
cp -r ./Release/Lilu.kext ./VirtualSMC
cp -r ./Release/Lilu.kext ./MacHyperVSupport
cp -r ./Release/Lilu.kext ./BrcmPatchRAM
cp -r ./Release/Lilu.kext ./VoodooInput
cp -r ./Release/Lilu.kext ./ThunderboltFixup
cp -r ./Release/Lilu.kext ./ForgedInvariant
cp -r ./Release/Lilu.kext ./NootedRed
cp -r ./Release/Lilu.kext ./CpuTopologyRebuild

echo "            "
echo "##### !!! COPY MacKernelSDK TO FOLDERS !!! #####"
echo "            "
cd /$HOME/Desktop/Lilu4All
cp -r ./MacKernelSDK ./RestrictEvents
cp -r ./MacKernelSDK ./AppleALC
cp -r ./MacKernelSDK ./AirportBrcmFixup
cp -r ./MacKernelSDK ./EmeraldSDHC
cp -r ./MacKernelSDK ./WhateverGreen
cp -r ./MacKernelSDK ./NVMeFix
cp -r ./MacKernelSDK ./BrightnessKeys
cp -r ./MacKernelSDK ./HibernationFixup
cp -r ./MacKernelSDK ./DebugEnhancer
cp -r ./MacKernelSDK ./CpuTscSync
cp -r ./MacKernelSDK ./CryptexFixup
cp -r ./MacKernelSDK ./FeatureUnlock
cp -r ./MacKernelSDK ./CPUFriend
cp -r ./MacKernelSDK ./IntelMausi
cp -r ./MacKernelSDK ./RTCMemoryFixup
cp -r ./MacKernelSDK ./VirtualSMC
cp -r ./MacKernelSDK ./MacHyperVSupport
cp -r ./MacKernelSDK ./VoodooPS2
cp -r ./MacKernelSDK ./BrcmPatchRAM
cp -r ./MacKernelSDK ./VoodooInput
cp -r ./MacKernelSDK ./ThunderboltFixup
cp -r ./MacKernelSDK ./ForgedInvariant
cp -r ./MacKernelSDK ./NootedRed
cp -r ./MacKernelSDK ./CpuTopologyRebuild

echo "            "
echo "##### !!! START BUILD FILES !!! #####"
echo "            "
cd /$HOME/Desktop/Lilu4All/RestrictEvents/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/AppleALC/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/AirportBrcmFixup/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/EmeraldSDHC/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/WhateverGreen/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/NVMeFix/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/BrightnessKeys/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/HibernationFixup/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/DebugEnhancer/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/CpuTscSync/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/CryptexFixup/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/FeatureUnlock/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/CPUFriend/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/IntelMausi/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/RTCMemoryFixup/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/VirtualSMC/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/MacHyperVSupport/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/VoodooPS2/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/BrcmPatchRAM/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/VoodooInput/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/Lilu/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/ForgedInvariant/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/NootedRed/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/ThunderboltFixup/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/CpuTopologyRebuild/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release
cd /$HOME/Desktop/Lilu4All/RTL8111_driver_for_OS_X/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release/package/Kexts
cd /$HOME/Desktop/Lilu4All/AtherosE2200Ethernet/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release/package/Kexts
cd /$HOME/Desktop/Lilu4All/RealtekRTL8100/
xcodebuild CONFIGURATION_BUILD_DIR=/$HOME/Desktop/Lilu4All/Release/package/Kexts

cp -R ~/Desktop/Lilu4All/Release/package/Kexts/RealtekRTL8111.kext ~/Desktop/Lilu4All/Release
cp -R ~/Desktop/Lilu4All/Release/package/Kexts/AtherosE2200Ethernet.kext ~/Desktop/Lilu4All/Release
cp -R ~/Desktop/Lilu4All/Release/package/Kexts/RealtekRTL8100.kext ~/Desktop/Lilu4All/Release

cd ~/Desktop/Lilu4All/Release
rm -rf *.dSYM
rm -rf *.zip
rm -rf *dSYM
rm -rf *.dsl
rm -rf *.dylib
rm -rf DeviceGenerator
rm -rf ResourceConverter
rm -rf rtcread
rm -rf smc
rm -rf fanpwmgen
rm -rf hvfilecopyd
rm -rf hvshutdownd
rm -rf hvtimesyncd
rm -rf alc-verb
rm -rf smcread
rm -rf package
rm -rf Instructions.md

mv ~/Desktop/Lilu4All/Release ~/Desktop/

cd ~/Desktop
rm -rf Lilu4All

osascript <<EOT
tell application "Finder"
 activate
 display alert "Files generated in your Desktop inside Release folder!"
end tell
EOT